package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.CdkExchangeRecordVO;
import com.sc.nft.entity.vo.ProductCdkRecordVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.ProductCdkRecord;
import com.sc.nft.mapper.ProductCdkRecordMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_product_cdk_record)数据DAO
 *
 * @author Sun
 * @since 2022-08-22 16:34:19
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class ProductCdkRecordDao extends ServiceImpl<ProductCdkRecordMapper, ProductCdkRecord> {

    public List<ProductCdkRecord> getListByUserIdAndProductId(Long userId,Long productId) {
        LambdaQueryWrapper<ProductCdkRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProductCdkRecord::getUserId,userId);
        wrapper.eq(ProductCdkRecord::getProductId,productId);
        return list(wrapper);
    }

    public Page<ProductCdkRecordVO> getUserExchangeListByPage(Long userId,  Page page) {
        return baseMapper.getUserExchangeListByPage(page,userId);
    }

    public Integer getCountByCdkActivityId(Long id) {
        LambdaQueryWrapper<ProductCdkRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProductCdkRecord::getCdkActivityId,id);
        return count(wrapper);
    }

    /**
     * 后台查询兑换记录
     * @param page
     * @param userTel
     * @param cdk
     * @param cdkActivityId
     * @return
     */
    public Page<CdkExchangeRecordVO> adminCdkExchangeRecord(Page page, String userTel, String cdk,Long cdkActivityId) {
        return baseMapper.adminCdkExchangeRecord(page,userTel,cdk,cdkActivityId);
    }

    /**
     * 判断用户自定义兑换码使用了多少次
     * @param userId
     * @param activityId
     * @return
     */
    public Integer getListByUserIdAndActivityId(Long userId, Long activityId) {
        return baseMapper.getListByUserIdAndActivityId(userId,activityId);
    }
}